package com.ruoyi.memberSer.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.memberSer.domain.MemberSer;
import com.ruoyi.memberSer.service.IMemberSerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务号用户Controller
 *
 * @author ch
 * @date 2021-12-27
 */
@RestController
@RequestMapping("/memberSer/memberSer")
public class MemberSerController extends BaseController
{
    @Autowired
    private IMemberSerService memberSerService;

    /**
     * 查询服务号用户列表
     */
    @PreAuthorize("@ss.hasPermi('memberSer:memberSer:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberSer memberSer)
    {
        startPage();
        List<MemberSer> list = memberSerService.selectMemberSerList(memberSer);
        return getDataTable(list);
    }

    /**
     * 导出服务号用户列表
     */
    @PreAuthorize("@ss.hasPermi('memberSer:memberSer:export')")
    @Log(title = "服务号用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MemberSer memberSer)
    {
        List<MemberSer> list = memberSerService.selectMemberSerList(memberSer);
        ExcelUtil<MemberSer> util = new ExcelUtil<MemberSer>(MemberSer.class);
        return util.exportExcel(list, "服务号用户数据");
    }

    /**
     * 获取服务号用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('memberSer:memberSer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(memberSerService.selectMemberSerById(id));
    }

    /**
     * 新增服务号用户
     */
    @PreAuthorize("@ss.hasPermi('memberSer:memberSer:add')")
    @Log(title = "服务号用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberSer memberSer)
    {
        return toAjax(memberSerService.insertMemberSer(memberSer));
    }

    /**
     * 修改服务号用户
     */
    @PreAuthorize("@ss.hasPermi('memberSer:memberSer:edit')")
    @Log(title = "服务号用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberSer memberSer)
    {
        memberSer.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(memberSerService.updateMemberSer(memberSer));
    }

    /**
     * 删除服务号用户
     */
    @PreAuthorize("@ss.hasPermi('memberSer:memberSer:remove')")
    @Log(title = "服务号用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(memberSerService.logicDeleteMemberSer(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
